import 'package:flutter/material.dart';

mixin DraggablePositionedMixin<T extends StatefulWidget> on State<T> {
  Offset defaultPosition = Offset(70.0, 300.0);
  Offset _dragPosition = Offset(0.0, 0.0);

  Widget get draggableChild;

  Widget get draggable {
    return Positioned(
      left: defaultPosition.dx + _dragPosition.dx,
      top: defaultPosition.dy + _dragPosition.dy,
      child: GestureDetector(
        onPanStart: (details) {
          setState(() {
            _dragPosition = Offset(0.0, 0.0);
          });
        },
        onPanUpdate: (details) {
          setState(() {
            _dragPosition += details.delta;
          });
        },
        onPanEnd: (details) {
          setState(() {
            defaultPosition += _dragPosition;
            _dragPosition = Offset(0.0, 0.0);
          });
        },
        child: draggableChild,
      ),
    );
  }
}
